package example.simple_mindmap.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import example.simple_mindmap.domain.po.MindMap;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MindMapMapper extends BaseMapper<MindMap> {
    //获取所有导图，根据用户id
    @Select("select * from t_mindmap where uid=#{uid} order by isTop desc,updateTime desc limit #{start},#{capacity}")
    List<MindMap> selectAllByUid(@Param("uid")long uid,@Param("start") int start,@Param("capacity") int capacity);

    //获取所有公开导图，根据用户id
    @Select("select * from t_mindmap where uid=#{uid} and state=1 order by isTop desc,updateTime desc limit #{start},#{capacity}")
    List<MindMap> selectPublicAllByUid(@Param("uid")long uid,@Param("start") int start,@Param("capacity") int capacity);

    //获取所有公开导图
    @Select("select * from t_mindmap where state=1 and id<1000 order by (`like`*106+collect*16+ `view`) desc limit #{start},#{capacity}")
    List<MindMap> selectPublicAll(@Param("start") int start,@Param("capacity") int capacity);

    //删除图片URL，根据mid
    @Delete("delete from t_mindMap_image where mid=#{mid}")
    int deleteImage(@Param("mid") long mid);
    //获取图片URL，根据mid
    @Select("select url from t_mindMap_image where mid=#{mid}")
    List<String> selectAllImage(@Param("mid")Long mid);
    //获取此导图保存的图片数量
    @Select("select COUNT(mid) from t_mindMap_image where mid=#{mid}")
    int selectCountImage(@Param("mid")Long mid);
    //保存图片URL
    @Insert("insert into t_mindMap_image(mid, url)" +
            "values(#{mid}, #{url})")
    int insertImage(@Param("mid") Long mid,@Param("url") String url);
}
